<template>
    <div>
<ul id="treedeviceoperation" class="ztree"></ul>
 <input type="hidden" id="device_id" value="">
</div>
</template>
<style>

</style>
<script>

export default {
    data(){
        return{
        }
    },
     mounted(){
        domain.staticzt=false;
     }
};
     var setting = {
            view: {
               // addHoverDom: addHoverDom,
                removeHoverDom: removeHoverDom,
               selectedMulti: false
            },
       
            check: {
                enable: false,
             
            },
            data: {
                simpleData: {
                    enable: false
                }
            },
            edit: {
                enable: false,
                showRemoveBtn: false
            },
                check: {
　　　　enable: false,

},
              callback: {
        beforeClick: beforeClick,
       
    }
        };

        function beforeClick(treeId, treeNode){
         $("#usnameval").val("");
coidval=treeNode.id;
      if(treeNode.type=="0"){
   
      var node = treeNode.getParentNode();
  
         coidval=node.id;
         
      }

   pageval=1; 
    
    
    cxlist();
    return false;
};

     	var zNodes =[
			{ name:"父节点1 - 展开", open:true,
				children: [
					
							{ name:"叶子节点111"},
							{ name:"叶子节点112"},
							{ name:"叶子节点113"},
							{ name:"叶子节点114"}
                        ],
            }
					

		];
        $(document).ready(function(){ 
            $.fn.zTree.init($("#treedeviceoperation"), setting, zNodes);
            domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl+"/Threeinjection/DeviceManagement/queryCompanyandDevice",
                data: {"sessionid":sessionStorage.getItem("sid"),"coid":sessionStorage.getItem("coid")},
                datatype:"JSON",
                success: function (response) {  
                // alert(response);
                   var obj = eval("("+response+")");
                   // console.log(response);
                    var newTree=$.fn.zTree.init($("#treedeviceoperation"), setting, JSON.parse(obj.companyandDevice));
                }
            });

            console.log("在设备操作里")
        });

function beforeEditName(treeId, treeNode) {
 $("#myModalLabel").text("修改");

   $("#update").click();
	return false;
}



function onRename(e, treeId, treeNode, isCancel) {
//alert(treeNode.name);
}
        var newCount = 1;
        function addHoverDom(treeId, treeNode) {
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='add node' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            var btn = $("#addBtn_"+treeNode.tId);
            if (btn) btn.bind("click", function(){
              

                var zTree = $.fn.zTree.getZTreeObj("treedeviceoperation");
$("#update").click();
 $(".form-group").eq(1).show();
        try{
           var pNode = treeNode.getParentNode();
        
           $("#co_name").val(treeNode.name);
             $("#company_name").val(pNode.name);
                $("#company_id").val(pNode.id);
    
        }catch(ex){

         $(".form-group").eq(2).hide();
        
        }
            if(typeof(pNode.name)!="undefined")
               
            //  zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
                return false;
            });
        };
        
        function removeHoverDom(treeId, treeNode) {
          $("#addBtn_"+treeNode.tId).unbind().remove();
       };
        //-->

</script>